package com.ruoyi.eam.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.eam.doman.EamAsset;
import com.ruoyi.eam.mapper.EamAssetMapper;
import com.ruoyi.eam.mapper.EamTypeMapper;
import com.ruoyi.eam.service.IEamAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 固定资产Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@Service
public class EamAssetServiceImpl implements IEamAssetService
{
    @Resource
    private EamAssetMapper eamAssetMapper;

    @Resource
    private EamTypeMapper eamTypeMapper;

    /**
     * 查询固定资产
     *
     * @param assetId 固定资产主键
     * @return 固定资产
     */
    @Override
    public EamAsset selectEamAssetByAssetId(Long assetId)
    {
        return eamAssetMapper.selectEamAssetByAssetId(assetId);
    }


    /**
     *
     * @param map
     * @return
     */
    @Override
    public List<EamAsset> selectEamAssetList(Map<String, Objects> map)
    {
        List<EamAsset> list = eamAssetMapper.selectEamAssetList(map);
        for (EamAsset eamAsset : list) {
            eamAsset.setEamType(eamTypeMapper.selectEamTypeByTypeId(eamAsset.getTypeId()));
        }
        return list;
    }

    /**
     * 新增固定资产
     *
     * @param eamAsset 固定资产
     * @return 结果
     */
    @Override
    public int insertEamAsset(EamAsset eamAsset)
    {
        eamAsset.setCreateTime(DateUtils.getNowDate());
        return eamAssetMapper.insertEamAsset(eamAsset);
    }

    /**
     * 修改固定资产
     *
     * @param eamAsset 固定资产
     * @return 结果
     */
    @Override
    public int updateEamAsset(EamAsset eamAsset)
    {
        return eamAssetMapper.updateEamAsset(eamAsset);
    }

    /**
     * 批量删除固定资产
     *
     * @param assetIds 需要删除的固定资产主键
     * @return 结果
     */
    @Override
    public int deleteEamAssetByAssetIds(Long[] assetIds)
    {
        return eamAssetMapper.deleteEamAssetByAssetIds(assetIds);
    }

    /**
     * 删除固定资产信息
     *
     * @param assetId 固定资产主键
     * @return 结果
     */
    @Override
    public int deleteEamAssetByAssetId(Long assetId)
    {
        return eamAssetMapper.deleteEamAssetByAssetId(assetId);
    }
}
